#ifndef SQUARE_H #define SQUARE_H #include using namespace std; class Square { public: Square(); // inspectors // report value at a given position int getVal(int row, int col); // report if a given position is open bool posOpen(int row, int col); // report if a given value is used bool valUsed(int val); // report whether the row is under value bool rowUnder (int row); // report whether the col is under value bool colUnder (int col); // report whether left diag is under value bool leftDiagUnder(); // report whether right diag is under value bool rightDiagUnder(); // return the sum for a row int rowSum(int row); // return the sum for a column int colSum (int col); // return the sum for the left to right diag int diagLeftSum(); // return the sum for the right to left diag int diagRightSum(); // check if the magic square is perfect bool checkSquare(); // check if the (possibly partial) magic square is bad already bool badSquare(); // report if beyond finding a value to place bool searchAtEnd(); // getters int getLastRowTried() { return lastRowTried; } int getLastColTried() { return lastColTried; } int getLastValTried() { return lastValTried; } int getFirstRowTried() { return firstRowTried; } int getFirstColTried() { return firstColTried; } int getFirstValTried() { return firstValTried; } // mutators // make sure the number isn't already being used // then if not put it in the requested position // (if the position is empty) bool place(int row, int col, int val); // take out a particular placement bool unplace(int row, int col); // take out the most recent placement bool unplace( ); // advance to next possible square - returning changed square Square nextPossSquare(); // advance to next non-bad square - // - a square that doesn't already have a violation // returning changed square Square nextNonBadSquare(); // setters void setLastRowTried(int val) { lastRowTried = val; } void setLastColTried(int val) { lastColTried = val; } void setLastValTried(int val) { lastValTried = val; } // setters void setFirstRowTried(int val) { firstRowTried = val; } void setFirstColTried(int val) { firstColTried = val; } void setFirstValTried(int val) { firstValTried = val; } private: int square[4][4]; // extra space so user can use 1-3 without us messing bool used[10]; // extra space so user can deal with 1-9 without us messing int numUsed; // number of digits used // for keeping track of what has been tried - to avoid looping // infinitely during search int lastRowTried; int lastColTried; int lastValTried; int firstRowTried; int firstColTried; int firstValTried; }; ostream & operator << (ostream & out, Square & aSquare); // output a textual representation of a Square #endif